package com.isunland.managesystem.entity;

import android.content.Context;
import android.content.Intent;
import com.isunland.managesystem.base.BaseModel;
import com.isunland.managesystem.base.BaseVolleyActivity;
import com.isunland.managesystem.common.DynamicConfigLab;
import com.isunland.managesystem.utils.MyStringUtil;
import com.isunland.managesystem.utils.SharedPreferencesUtil;

/**
 * 对象功能:
 * 开发公司: 北京信普达系统工程有限公司
 * 开发人员: wangyanan
 * 创建时间: 2017/6/3 23:46
 */

@SuppressWarnings("unused") public class FunctionObject extends BaseModel {
  /** 服务端动态配置的key */
  private String dynamicKey;
  /** 服务端的alias */
  private int code;
  private String title;
  /** 提醒的code,默认和alias一致 */
  private int hintCode;
  /** 提醒的数量,每次进入菜单页面更新 */
  private int hintNumber;
  private Intent intent;
  private BaseParams mParams;

  public FunctionObject(int code, String title, Intent intent) {
    //hintcode默认是code
    this(code, code, title, intent, "", null);
  }

  public FunctionObject(int code, String title, Intent intent, BaseParams params) {
    this(code, code, title, intent, "", params);
  }

  public FunctionObject(int code, int hintCode, String title, Intent intent, BaseParams params) {
    this(code, hintCode, title, intent, "", params);
  }

  public FunctionObject() {
  }

  public FunctionObject(int code, String title, Intent intent, String dynamicKey) {
    //hintcode默认是code
    this(code, code, title, intent, dynamicKey, null);
  }

  public FunctionObject(int code, int hintCode, String title, Intent intent) {
    this(code, hintCode, title, intent, "", null);
  }

  /** 如果params不为空,自动设置标题为title */
  private FunctionObject(int code, int hintCode, String title, Intent intent, String dynamicKey,
      BaseParams params) {
    this.code = code;
    this.title = title;
    this.hintCode = hintCode;
    this.intent = intent;
    this.dynamicKey = dynamicKey;
    if (params != null) params.setTitle(title);//自动生成标题.
    this.mParams = params;
  }

  public BaseParams getParams() {
    return mParams;
  }

  public void setParams(BaseParams mParams) {
    this.mParams = mParams;
  }

  public String getDynamicKey() {
    return dynamicKey;
  }

  public void setDynamicKey(String dynamicKey) {
    this.dynamicKey = dynamicKey;
  }

  public Intent getIntent() {
    return intent;
  }

  public void setIntent(Intent intent) {
    this.intent = intent;
  }

  public int getHintNumber() {
    return hintNumber;
  }

  public void setHintNumber(int hintNumber) {
    this.hintNumber = hintNumber;
  }

  public int getHintCode() {
    return hintCode;
  }

  public void setHintCode(int hintCode) {
    this.hintCode = hintCode;
  }

  public int getCode() {
    return code;
  }

  public void setCode(int code) {
    this.code = code;
  }

  public String getTitle() {
    return title;
  }

  public void setTitle(String title) {
    this.title = title;
  }

  @Override public String toString() {
    return title;
  }

  /** 执行服务端动态配置 */
  public void excuteDynamic(BaseVolleyActivity context) {
    if (context == null || MyStringUtil.isEmpty(dynamicKey)) return;
    DynamicConfigLab.clearMap();//每次进入,清空配置信息,因为配置可能有变化,
    DynamicConfigLab.newInstance(context, dynamicKey);
  }

  /** 设置sp */
  public void setSharedPreference(Context context) {
    if (context == null) return;
    //用于区分农机和农技
    if (code == 2002) {
      SharedPreferencesUtil.setString(context, SharedPreferencesUtil.KEY_FORUM_SUBCODE, "02");
    }
    if (code == 2003 || code == 2016 || code == 2017) {
      SharedPreferencesUtil.setString(context, SharedPreferencesUtil.KEY_FORUM_SUBCODE, "01");
    }
  }

  public String getActivityClassName() {
    if (intent == null) return null;
    return intent.getComponent().getClassName();
  }

  //public Class getActivityClass() {
  //  if (intent == null) return null;
  //  return intent.getComponent().getClass();
  //}
}
